<%--
  Created by IntelliJ IDEA.
  User: 六处
  Date: 2021/7/25
  Time: 9:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/add.css"/>
</head>
<body>
<div id="app">
    <div class="header">
        <span>修改快递员</span>
    </div>
    <div class="content">
        <table>
            <tr>
                <td class="text-right">手机号码</td><td class="content_right"><input class="input inline-input" placeholder="请输入手机号码"> <span onclick="form01Submit()" class="btn btn-info">立即查找</span></td>
            </tr>
        </table>
    </div>


    <div class="header">
        <span>查找信息如下</span>
    </div>
    <div class="content" id="content">
        <table>
            <tr>
                <td class="text-right">姓名</td><td class="content_right"><input class="input" placeholder="请输入姓名" onblur="userTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td class="text-right">手机号码</td><td class="content_right"><input class="input" placeholder="请输入手机号码" onblur="phoneTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td class="text-right">身份证号码</td><td class="content_right"><input class="input" placeholder="请输入身份证号码" onblur="cardIdTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td class="text-right">密码</td><td class="content_right"><input class="input" placeholder="请输入密码" onblur="pwdTest()"><button hidden disabled></button></td>
            </tr>
            <tr>
                <td></td><td class="content_right"><span class="btn btn-info" onclick="form02Submit()">立即修改</span> <span class="btn" onclick="reset()">重置</span> </td>
            </tr>
        </table>
        <input type="hidden" />
    </div>
</div>

<script src="../../js/jquery-1.11.1.js"></script>
<script src="../../layer/layer.js"></script>
<script src="../../assets/layui.all.js"></script>
<script>
    $(function () {
        reset();
    });
    function reset() {
        $("input").val("");
        $("#content").css("display","none");
    }
    function form01Submit () {
        var windowId = layer.load(5);
        var num = $("input:eq(0)").val();
        num=$.trim(num);
        $.post("/user/findByPhone.do",{
            phone:num
        },function (data) {
            layer.close(windowId);
            if(data["msgCode"]==200){
                $("#content").css("display","");
                $("input:eq(1)").val(data["dataList"][0]["userName"]);
                $("input:eq(2)").val(data["dataList"][0]["userPhone"]);
                $("input:eq(3)").val(data["dataList"][0]["cardId"]);
                $("input:eq(4)").val(data["dataList"][0]["userPwd"]);
                $("input:eq(5)").val(data["dataList"][0]["userId"]);
                layer.alert("成功查寻到此用户！٩(๑>◡<๑)۶ ");
            }else if (data["msgCode"]==400){
                layer.alert("未查到此用户！(〒︿〒)");
            }
        },"json");
        return false;
    }
    function form02Submit() {
        var windowId = layer.load();
        var userName = $("input:eq(1)").val();
        var userPhone = $("input:eq(2)").val();
        var cardId = $("input:eq(3)").val();
        var userPwd = $("input:eq(4)").val();
        var userId = $("input:eq(5)").val();
        $.post("/user/update.do",{
            userName:userName,
            phone:userPhone,
            cardId:cardId,
            userPwd:userPwd,
            userId:userId
        },function (data) {
            layer.close(windowId);
            if (data["msgCode"] == 200){
                layer.alert("修改成功~   ヾ(^Д^*)/");
            }else {
                layer.alert(data["msgContent"]);
                layer.alert("修改失败了  (；´д｀)ゞ");
            }
        },"json");
        return false;
    }
</script>
<script>
    function userTest () {
        var str = $("input:eq(1)").val();
        str=$.trim(str);
        var ret = /^[\u4e00-\u9fa5]{2,6}$/;
        if (!ret.test(str)) {
            $("button:eq(0)").html("姓名不合法或已存在！");
            $("button:eq(0)").css("display","inline-block");
            $("button:eq(0)").css("color","red");
            $("button:eq(0)").css("font-size","28");
            return false;
        }
        $.getJSON("/user/findByUserName.do",{userName:str},function (data) {
            if(data["msgCode"]==400){
                $("button:eq(0)").html("正确");
                $("button:eq(0)").css("display","inline-block");
                $("button:eq(0)").css("color","green");
                $("button:eq(0)").css("font-size","28");
                return true;
            }else {
                $("button:eq(0)").html("已存在");
                $("button:eq(0)").css("display","inline-block");
                $("button:eq(0)").css("color","red");
                $("button:eq(0)").css("font-size","28");
            }
            return false;
        });
    }
    function phoneTest () {
        var str = $("input:eq(2)").val();
        str=$.trim(str);
        var ret = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
        if (!ret.test(str)) {
            $("button:eq(1)").html("手机号不合法或已存在！");
            $("button:eq(1)").css("display","inline-block");
            $("button:eq(1)").css("color","red");
            $("button:eq(1)").css("font-size","28");
            return;
        }
        $.getJSON("/user/findByPhone.do",{phone:str},function (data) {
            if(data["msgCode"]==400){
                $("button:eq(1)").html("正确");
                $("button:eq(1)").css("display","inline-block");
                $("button:eq(1)").css("color","green");
                $("button:eq(1)").css("font-size","28");
                return true;
            }else {
                $("button:eq(1)").html("已存在");
                $("button:eq(1)").css("display","inline-block");
                $("button:eq(1)").css("color","red");
                $("button:eq(1)").css("font-size","28");
                return true;
            }
            return false;
        });
    };
    function cardIdTest () {
        var str = $("input:eq(3)").val();
        str=$.trim(str);
        var ret = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if (!ret.test(str)) {
            $("button:eq(2)").html("身份证不合法(正确：应为15位、18位数字)或已存在");
            $("button:eq(2)").css("display","inline-block");
            $("button:eq(2)").css("color","red");
            $("button:eq(2)").css("font-size","28");
            return;
        }
        $.getJSON("/user/findByCardId.do",{cardId:str},function (data) {
            if(data["msgCode"]==400){
                $("button:eq(2)").html("正确");
                $("button:eq(2)").css("display","inline-block");
                $("button:eq(2)").css("color","green");
                $("button:eq(2)").css("font-size","28");
                return true;
            }else{
                $("button:eq(2)").html("已存在");
                $("button:eq(2)").css("display","inline-block");
                $("button:eq(2)").css("color","red");
                $("button:eq(2)").css("font-size","28");
            }
        });
        return false;
    };
    function pwdTest () {
        var str = $("input:eq(4)").val();
        str=$.trim(str);
        var ret =  /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}$/;
        if (!ret.test(str)) {
            $("button:eq(3)").html("密码不合法（正确：必须包含大小写字母和数字的组合，可以使用特殊字符，长度在8-15之间）");
            $("button:eq(3)").css("display","inline-block");
            $("button:eq(3)").css("color","red");
            $("button:eq(3)").css("font-size","28");
            return false;
        }
        $("button:eq(3)").html("正确");
        $("button:eq(3)").css("display","inline-block");
        $("button:eq(3)").css("color","green");
        $("button:eq(3)").css("font-size","28");
        return true;
    };
</script>
</body>
</html>
